package com.iot.system.service.impl;

import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

import com.iot.common.utils.DateUtils;
import com.iot.system.domain.DeviceData;
import com.iot.system.domain.DeviceDetails;
import com.iot.system.mapper.DeviceDataMapper;
import com.iot.system.mapper.DeviceDetailsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.iot.system.mapper.DeviceStateMapper;
import com.iot.system.domain.DeviceState;
import com.iot.system.service.IDeviceStateService;
import org.springframework.util.CollectionUtils;

/**
 * 【请填写功能名称】Service业务层处理
 * 
 * @author iot
 * @date 2024-11-18
 */
@Service
public class DeviceStateServiceImpl implements IDeviceStateService 
{
    @Autowired
    private DeviceStateMapper deviceStateMapper;

    /**
     * 查询【请填写功能名称】
     * 
     * @param id 【请填写功能名称】主键
     * @return 【请填写功能名称】
     */
    @Override
    public DeviceState selectDeviceStateById(Long id)
    {
        return deviceStateMapper.selectDeviceStateById(id);
    }

    /**
     * 查询【请填写功能名称】列表
     * 
     * @param deviceState 【请填写功能名称】
     * @return 【请填写功能名称】
     */
    @Override
    public List<DeviceState> selectDeviceStateList(DeviceState deviceState)
    {
        return deviceStateMapper.selectDeviceStateList(deviceState);
    }

    /**
     * 新增【请填写功能名称】
     * 
     * @param deviceState 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int insertDeviceState(DeviceState deviceState)
    {
        deviceState.setCreateTime(DateUtils.getNowDate());
        return deviceStateMapper.insertDeviceState(deviceState);
    }

    /**
     * 修改【请填写功能名称】
     * 
     * @param deviceState 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int updateDeviceState(DeviceState deviceState)
    {
        deviceState.setUpdateTime(DateUtils.getNowDate());
        return deviceStateMapper.updateDeviceState(deviceState);
    }

    /**
     * 批量删除【请填写功能名称】
     * 
     * @param ids 需要删除的【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteDeviceStateByIds(Long[] ids)
    {
        return deviceStateMapper.deleteDeviceStateByIds(ids);
    }

    /**
     * 删除【请填写功能名称】信息
     * 
     * @param id 【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteDeviceStateById(Long id)
    {
        return deviceStateMapper.deleteDeviceStateById(id);
    }

    @Override
    public DeviceState getDeviceStateByDeviceId(Long deviceId) {
        DeviceState deviceState =  deviceStateMapper.selectDeviceStateByDeviceId(deviceId);
        if (Objects.isNull(deviceState)) {
            return new DeviceState();
        }
        return deviceState;
    }

    @Override
    public Integer getDeviceOlineStateTotal(List<Integer> deviceStateList ) {
        Integer deviceOlineStateTotal = deviceStateMapper.getDeviceOlineStateTotal(deviceStateList);
        if (Objects.nonNull(deviceOlineStateTotal)) {
            return deviceOlineStateTotal;
        }
        return null;
    }
}
